import { Config } from './config';
import * as $ from "../lib/jquery-3.2.0.min";

//调用接口
//xhrFields保存服务器cookie到本地的appliction
export const Api = {
    userPostHttp:(name,data,token)=>{
        return new Promise((resolve,reject)=>{
            $.ajax({
                url: `${Config.ip}/${name}`,
                type: "POST",
                xhrFields: { withCredentials: true },
                data: data,
                headers: {
                    Accept: token
                },
                success: (res) => {
                    resolve(res);
                },
                error:(err)=>{
                    reject(err);
                }
            });
        } )
    },

    userGetHttp:(name,data)=>{
        return new Promise((resolve,reject) => {
            $.ajax({
                url: `${Config.ip}/${name}`,
                data:data,
                type: "GET",
                success: (res) => {
                    resolve(res);
                },
                error:(err)=>{
                    reject(err);
                }
            });
        })
    },

    postHttp:(name,data,token)=>{
        console.log(data);
        return new Promise((resolve,reject)=>{
            $.ajax({
                url: `${Config.ip}/${name}`,
                type: "POST",
                data: data,
                headers: {
                    Accept: token
                },
                success: (res) => {
                    resolve(res);
                },
                error:(err)=>{
                    reject(err);
                }
            });
        } )
    },
    getBase:(fd)=>{
        $.ajax({
            url : '',
            type : 'post',
            data : fd,
            success : function(data){
                console.log(data)
            }
        })
    }

};